package com.lqr.wechat.activity;

import android.view.MenuItem;
import android.view.View;

import com.bridge.imconfig.NimFriendSDK;
import com.lqr.wechat.R;
import com.lqr.wechat.databinding.ActivityPostscriptBinding;
import com.lqr.wechat.utils.UIUtils;
import com.netease.nimlib.sdk.RequestCallback;
/**
 * @创建者 CSDN_LQR
 * @描述 附言
 */
public class PostscriptActivity extends BaseActivity {

    public String mAccount;//账号
    public String mMsg;//附言
    private ActivityPostscriptBinding binding ;
    @Override
    public void initListener() {
        binding.lyToolbar.btnOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showWaitingDialog("请稍等");
                mMsg = binding.etMsg.getText().toString();
                //发送添加好友请求
                NimFriendSDK.addFriend(mAccount, mMsg, new RequestCallback<Void>() {
                    @Override
                    public void onSuccess(Void param) {
                        hideWaitingDialog();
                        UIUtils.showToast("添加好友申请成功");
                        finish();
                    }

                    @Override
                    public void onFailed(int code) {
                        UIUtils.showToast("添加好友失败" + code);
                        hideWaitingDialog();
                    }

                    @Override
                    public void onException(Throwable exception) {
                        exception.printStackTrace();
                        hideWaitingDialog();
                    }
                });
            }
        });
        binding.ibClear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                binding.etMsg.setText("");
            }
        });
    }

    @Override
    protected int layoutId() {
        return R.layout.activity_postscript;
    }

    @Override
    public void init() {
        mAccount = getIntent().getStringExtra("account");
    }

    @Override
    public void initView() {
        binding = getBind() ;
        initToolbar();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    private void initToolbar() {
        binding.lyToolbar.toolbar.setNavigationIcon(R.mipmap.ic_back);
        setSupportActionBar(binding.lyToolbar.toolbar);
        getSupportActionBar().setTitle(UIUtils.getString(R.string.app_name));
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        binding.lyToolbar.btnOk.setVisibility(View.VISIBLE);
        binding.lyToolbar.btnOk.setText("发送");
    }
}
